package com.example.backend.api.controller;

import com.example.backend.api.common.Result;
import com.example.backend.api.service.impl.HealthServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
@RequestMapping("/api/health")
@CrossOrigin(origins = "*", maxAge = 3600)
public class HealthController {

    @Autowired
    private HealthServiceImpl healthServiceimpl;
    @GetMapping("/getall")
    public Result getAll(@RequestParam(value = "user_id", required = false) Integer userId,
                         @RequestParam(value = "start_date", required = false) String startDate,
                         @RequestParam(value = "end_date", required = false) String endDate,
                         @RequestParam(value = "dept_name", required = false) String deptName,
                         @RequestParam(value = "symptom" ,required = false) String symptom) {
        return healthServiceimpl.getAll(userId, startDate, endDate, deptName, symptom);
    }
    @GetMapping("groupinfo")
    public Result getGroupInfo(@RequestParam(value ="day") String day){
        return healthServiceimpl.getGroupInfo(day);
    }

    @PostMapping("add")
    public Result addHealth(@RequestParam(value = "user_id") Integer userId,
                            @RequestParam(value="name") String name,
                            @RequestParam(value = "temperature") Float temperature,
                            @RequestParam(value = "symptom") String symptom,
                            @RequestParam(value = "date") String date,
                            @RequestParam(value = "dept_id") Integer deptId,
                            @RequestParam(value = "remark" ,required = false) String remark) throws ParseException {
        return healthServiceimpl.addHealth(userId,name,temperature,symptom,date,deptId,remark);
    }
}
